package com.sweetest.luffy.task;

import com.sweetest.luffy.entity.UserLine;
import com.sweetest.luffy.service.IUserLineService;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Component
@EnableScheduling
public class TaxiTask {

    @Resource
    private IUserLineService userLineService;

    //计算 邀请新用户
    @Scheduled(cron = "0 0/1 * * * *")
    public void inviteTask() {
        List<UserLine> list = userLineService.list();
        Date date = new Date();
        for (UserLine userLine : list) {
            if (0 == userLine.getStatus() && date.after(userLine.getStartDate())) {
                userLine.setStatus(1);
                userLineService.updateById(userLine);
            }
        }
    }

}
